﻿<%@ Page Title="" Language="C#" MasterPageFile="~/administrator/backend.Master" AutoEventWireup="true" CodeBehind="classroom-list.aspx.cs" Inherits="VQWEB.administrator.english.classroom.classroom_list" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Content_backend" runat="server">
  <div class="table-responsive">       
    </div>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Script_backend" runat="server">
   <script type="text/javascript">
       ShowToolBar("add");
       var url_ashx = "/admin/english/classroom/handler";
       var url_list = '<%=ResolveUrl("~/administrator/templates/list.tpl") %>';
       $(document).ready(function () {
           $.get(url_ashx, { list_classroom: "list_classroom" }, function (data) {
               list(data);
           });
       });

       $(document).on("click", "#btnAdd", function () {
           window.location = "/admin/english/classroom/add";
       });

       $(document).on("click", "#btnEdit", function () {
           var Id = $("input[name='chkItem']:checked").first().attr("value");
           if (Id != undefined)
               window.location = "/admin/english/classroom/edit/" + Id;
       });
       //LockUnLock
       $(document).on("click", "#btnLockUnlock", function () {
           var array = InputChecked();
           if (array.length > 0) {
               $.post(url_ashx, { lockunlock_classroom: JSON.stringify(array) }, function (data) {
                   list(data);
               });
           }
       });
       //Delete
       $(document).on("click", "#btnDelete", function (e) {
           var array = InputChecked();
           if (array.length > 0) {
               if (confirm("Bạn muốn xóa bản ghi không ???")) {
                   $.post(url_ashx, { delete_classroom: JSON.stringify(array) }, function (data) {
                       list(data);
                   });
               }
           }

       });

       //List
       function list(data) {
           var plusData = $.parseJSON(data);
           var columns = ["STT", "<input name='chkAll' value='' type='checkbox'>", "Title", "Content", "Active"];
           var rows = new Array();
           $.each(plusData, function (i, obj) {
               var row = [];
               var active = (obj.active) ? "active" : "notactive";
               var url = "<a href=/admin/english/classroom/view/" + obj.id + ">" + obj.title + "</a>";
               var checkbox = "<input name='chkItem' type='checkbox'  value=" + obj.id + ">";
               row.push(i + 1);
               row.push(checkbox);
               row.push(url);
               row.push(obj.content);
               row.push(active);
               rows.push(row);
           });
           $('div.table-responsive').empty();
           $.jqoteload(url_list, function (templates) {
               $('div.table-responsive').jqoteapp(templates.list_tpl, { columns: columns, rows: rows });
           });
       }
    </script>
</asp:Content>
